﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
namespace WebBanDT.AdminControl
{
    public partial class ThemSuaXoaUser : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                Load_data();
            }
        }
        LayUser ds = new LayUser();
        ThemUser updateuser = new ThemUser();
        protected void Load_data()
        {
            Repeater1.DataSource = ds.layallUser();
            Repeater1.DataBind();
        }
        protected void Thucthi(object sender, RepeaterCommandEventArgs e)
        {

            if (e.CommandName == "Sua")
            {
                ((Label)e.Item.FindControl("lblEmail")).Visible = true;
                ((TextBox)e.Item.FindControl("txtEmail")).Visible = false;

                ((Label)e.Item.FindControl("lblMatKhau")).Visible = false;
                ((TextBox)e.Item.FindControl("txtMatKhau")).Visible = true;

                ((Label)e.Item.FindControl("lblHoten")).Visible = false;
                ((TextBox)e.Item.FindControl("txtHoten")).Visible = true;

                ((Label)e.Item.FindControl("lblDiaChi")).Visible = false;
                ((TextBox)e.Item.FindControl("txtDiaChi")).Visible = true;

                ((Label)e.Item.FindControl("lblSoDT")).Visible = false;
                ((TextBox)e.Item.FindControl("txtSoDT")).Visible = true;

                ((Label)e.Item.FindControl("lblSoFax")).Visible = false;
                ((TextBox)e.Item.FindControl("txtSoFax")).Visible = true;

                ((Label)e.Item.FindControl("lnlPhanQuyen")).Visible = false;
                ((TextBox)e.Item.FindControl("txtPhanquyen")).Visible = true;

                ((LinkButton)e.Item.FindControl("LinkButton1")).Visible = false;
                ((LinkButton)e.Item.FindControl("lbtn1")).Visible = false;
                ((LinkButton)e.Item.FindControl("LinkButton2")).Visible = true;
                ((LinkButton)e.Item.FindControl("LinkButton3")).Visible = true;
            }
            if (e.CommandName == "Luu")
            {
                try
                {
                    int phanquyen = int.Parse(((TextBox)e.Item.FindControl("txtPhanquyen")).Text);
                    updateuser.SuaNguoiDung(((TextBox)e.Item.FindControl("txtEmail")).Text, ((TextBox)e.Item.FindControl("txtMatKhau")).Text, ((TextBox)e.Item.FindControl("txtHoten")).Text,((TextBox)e.Item.FindControl("txtDiaChi")).Text, ((TextBox)e.Item.FindControl("txtSoDT")).Text, ((TextBox)e.Item.FindControl("txtSoFax")).Text, phanquyen);
                    Load_data();
                }
                catch (Exception)
                {

                    throw;
                }

            }
            if (e.CommandName == "Xoa")
            {

                try
                {
                    updateuser.XoaNguoiDung(((TextBox)e.Item.FindControl("txtEmail")).Text);
                    Load_data();

                }
                catch (Exception)
                {

                }
            }
            if (e.CommandName == "Khongluu")
            {
                ((Label)e.Item.FindControl("lblEmail")).Visible = true;
                ((TextBox)e.Item.FindControl("txtEmail")).Visible = false;

                ((Label)e.Item.FindControl("lblMatKhau")).Visible = true;
                ((TextBox)e.Item.FindControl("txtMatKhau")).Visible = false;

                ((Label)e.Item.FindControl("lblHoten")).Visible = true;
                ((TextBox)e.Item.FindControl("txtHoten")).Visible = false;

                ((Label)e.Item.FindControl("lblDiaChi")).Visible = true;
                ((TextBox)e.Item.FindControl("txtDiaChi")).Visible = false;

                ((Label)e.Item.FindControl("lblSoDT")).Visible = true;
                ((TextBox)e.Item.FindControl("txtSoDT")).Visible = false;

                ((Label)e.Item.FindControl("lblSoFax")).Visible = true;
                ((TextBox)e.Item.FindControl("txtSoFax")).Visible = false;

                ((Label)e.Item.FindControl("lnlPhanQuyen")).Visible = true;
                ((TextBox)e.Item.FindControl("txtPhanquyen")).Visible = false;

                ((LinkButton)e.Item.FindControl("LinkButton1")).Visible = true;
                ((LinkButton)e.Item.FindControl("lbtn1")).Visible = false;
                ((LinkButton)e.Item.FindControl("LinkButton2")).Visible = false;
                ((LinkButton)e.Item.FindControl("LinkButton3")).Visible = false;
            }
        }
    }
}